﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TowerDefender.Model;

namespace TowerDefender.Entities
{
    public class Peon
    {
        private Coordinates _coordinates;
        private int positionInMapPath = 0;
        private int _speed;
        private Map _map;
        private Engine _engine;
        public int direction;
        public event EventHandler CoordinatesChanged;

        public Peon(Map map, Engine engine, int speed)
        {
            _speed = speed;
            _map = map;
            _engine = engine;
            _engine.Tick += new EventHandler(engine_Tick);
            _coordinates = _map.MapPath.Steps[0];
        }

        public Coordinates coordinates 
        {
            get
            {
                return _coordinates;
            }
            set 
            { 
                _coordinates = value;
                if (CoordinatesChanged != null)
                {
                    CoordinatesChanged(this, new EventArgs());
                }
            }
        }

        void engine_Tick(object sender, EventArgs e)
        {
            if (_engine.TickCount % _speed == 0)
            {

                if (positionInMapPath < _map.MapPath.Steps.Count)
                {
                    this.coordinates = _map.MapPath.Steps[positionInMapPath++];
                }
            }
        }
    }
}
